import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
type imgType = {
    src: string,
    title: string
}
export const settingStore = defineStore('setting', {
    state: () => ({
        downloadLocation: 'D:\\壁纸',
        historyImgs: [] as Array<imgType>,
        collectionImgs: [] as Array<imgType>,
        imgDuration: 600,
        imgAnimationStart: 30,
        rightClickFunction: 'None',
        imgFormat: 'image/jpeg'
    }),
    // 开始数据持久化
    persist: true,
    actions: {
        deleteHistoryImg(item: any) {
            this.historyImgs = this.historyImgs.filter((img) => img.src !== item.src)
        },
        addCollectionImgs(item: any) {
            // 判断是否已经收藏
            if (this.collectionImgs.some((img) => img.src === item.src)) {
                ElMessage({
                    message: '取消收藏',
                    type: 'warning',
                    plain: true,
                })
                this.collectionImgs = this.collectionImgs.filter((img) => img.src !== item.src)
            } else {
                ElMessage({
                    message: '收藏成功',
                    type: 'success',
                    plain: true,
                })
                this.collectionImgs.unshift(item)
            }
        },
        clearCollectionImg() {
            this.collectionImgs = []
        }
    },
})
